package com.wyp.service.impl;


import com.wyp.dao.MSGoodsMapper;
import com.wyp.entity.MSGoods;
import com.wyp.service.MSGoodsService;
import com.wyp.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: Oliver
 */
@Service
public class MSGoodsServiceImpl implements MSGoodsService {
    @Autowired
    MSGoodsMapper MSGoodsMapper;

    @Override
    public boolean decrStock(GoodsVO goods) {
        MSGoods mGoods = new MSGoods();
        mGoods.setGoodsId(goods.getId());
        /**
         * 不能提前计算数量，当有多个线程同时进行时，一个线程获取到10,然后去数据库执行-1，然而数据库操作还没有完成，其他线程获取到的还是10，继续减1
         * 这样就无形增加了订单数量，
         */
        int rec = MSGoodsMapper.updateByGoodsId(mGoods);
        return rec > 0;
    }
}
